<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
<?php 
$layout = explode('&&&', file_get_contents('layout.html'));
echo $layout[0]
?>

<html>
<body>

<!-- Begin Main Column -->

<div id="mainContent">
	
<h2>
<?php
ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="rtl"; // Database name
$tbl_name="user"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword
$myusername=$_POST['username'];
$mypassword=md5($_POST['password']);

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE USERID='$myusername' and PASSWD='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
$get_access_level=mysql_query("SELECT AccessLevel FROM $tbl_name WHERE USERID='$myusername' and PASSWD='$mypassword'");
if (!$get_access_level) {
	die('Could not query:' . mysql_error());
}
$access_level=mysql_result($get_access_level, 0);
session_start();
$_SESSION['username'] = $myusername;
$_SESSION['level'] = $access_level;
echo "Login Successful";
}
else {
echo "Wrong Username or Password.";
}

ob_end_flush();

?>
</h2>
</div>

<!-- Begin Side Column -->
<!-- Begin Footer -->

<?php
echo $layout[1];
?>

</body>
</html>
